package com.huhuamin.leaf.controller;

import com.huhuamin.core.IdService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("id")
public class IdController {


    private final Map<String, IdService> idServiceMap;

    public IdController(Map<String, IdService> idServiceMap) {
        this.idServiceMap = idServiceMap;
    }

    @GetMapping("{strategy}/{key}")
    public String getKey(@PathVariable("strategy") String strategy, @PathVariable("key") String key) {
        return idServiceMap.get(strategy).getId(key);
    }
}
